<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
  xmlns:podcast="https://podcastindex.org/namespace/1.0"
>
  <channel>
    <title>Changelog++</title>
    <copyright>All rights reserved</copyright>
    <link>https://changelog.com/++</link>
    <language>en-us</language>
    <description>Thank you for subscribing to Changelog++!</description>
    <itunes:author>Changelog Media</itunes:author>
    <itunes:block>yes</itunes:block>
    <itunes:summary>Thank you for subscribing to Changelog++!</itunes:summary>
    <itunes:explicit>no</itunes:explicit>
    <itunes:image href="<%= url(~p"/images/podcasts/plusplus-original.png") %>"/>
    <itunes:category text="Technology">
      <itunes:category text="Software How-To"/>
      <itunes:category text="Tech News"/>
    </itunes:category>
    <%= for episode <- @episodes do %>
      <% url = if episode.plusplus_file, do: EpisodeView.plusplus_url(episode), else: EpisodeView.audio_url(episode) %>
      <% bytes = if episode.plusplus_file, do: episode.plusplus_bytes, else: episode.audio_bytes %>
      <% duration = if episode.plusplus_file, do: episode.plusplus_duration, else: episode.audio_duration %>
      <item>
        <title><%= episode_title(@podcast, episode) |> escaped() %></title>
        <link><%= url(~p"/#{episode.podcast.slug}/#{episode.slug}") %></link>
        <guid isPermaLink="false"><%= EpisodeView.guid(episode) %></guid>
        <pubDate><%= TimeView.rss(episode.published_at) %></pubDate>
        <enclosure url="<%= url %>" length="<%= bytes %>" type="audio/mpeg" />
        <description><%= SharedHelpers.md_to_text(episode.summary) %></description>
        <content:encoded><%= render("_show_notes.xml", episode: episode, plusplus: true) %></content:encoded>

        <itunes:episodeType><%= episode.type %></itunes:episodeType>
      <%= if episode.type == :full do %>
        <itunes:episode><%= EpisodeView.number(episode) %></itunes:episode>
      <% end %>
        <itunes:image href="<%= EpisodeView.cover_url(episode) %>"/>
        <itunes:duration><%= TimeView.duration(duration) %></itunes:duration>
        <itunes:explicit>no</itunes:explicit>
        <itunes:subtitle><%= escaped(episode.subtitle) %></itunes:subtitle>
        <itunes:summary><%= SharedHelpers.md_to_text(episode.summary) %></itunes:summary>
        <dc:creator>Changelog Media</dc:creator>
        <itunes:author>Changelog Media</itunes:author>
        <%= render_many(episode.hosts, __MODULE__, "_person.xml", as: :person, role: "host") %>
        <%= render_many(episode.guests, __MODULE__, "_person.xml", as: :person, role: "guest") %>
      <%= if Episode.has_transcript(episode) do %>
        <podcast:transcript url="<%= url(~p"/#{episode.podcast.slug}/#{episode.slug}/transcript") %>" type="text/html" />
      <% end %>
      <%= if Enum.any?(episode.plusplus_chapters) do %>
        <podcast:chapters url="<%= url(~p"/#{episode.podcast.slug}/#{episode.slug}/chapters?#{[pp: true]}") %>" type="application/json+chapters" />
        <atom:link rel="http://podlove.org/simple-chapters" href="<%= url(~p"/#{episode.podcast.slug}/#{episode.slug}/psc?#{[pp: true]}") %>" />
      <% end %>
      </item>
    <% end %>
  </channel>
</rss>
